package com.mlan.userap;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.util.Log;
import android.widget.Toast;

public class BootReceive extends BroadcastReceiver {
    public static final String TAG = "BootReceive";
    @Override
    public void onReceive(Context context, Intent intent) {
        if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
            Log.e(TAG, intent.getAction());
          //  Toast.makeText(context,"onReceiveonReceive BOOT_COMPLETEDBOOT_COMPLETEDBOOT_COMPLETEDBOOT_COMPLETED",Toast.LENGTH_LONG).show();
            ComponentName comp = new ComponentName(context.getPackageName(), LoginActivity.class.getName());
            context.startActivity(new Intent().setComponent(comp).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
        else if ("android.intent.action.intercept".equals(intent.getAction())) {
            String packname= intent.getStringExtra("packname");
            String appName=getAppName(packname);
            String toaststr = "【"+appName+"】不在白名单中已禁止启动";
            Toast.makeText(context,toaststr,Toast.LENGTH_LONG).show();
        }
        else {
            Log.e(TAG, "Received unexpected intent " + intent.toString());
            Toast.makeText(context,"onReceiveonReceive",Toast.LENGTH_LONG).show();
        }
    }
    private String getAppName(String pakgename) {
//        PackageManager pm = MyApplication.getApp().getPackageManager();
//        try {
//            ApplicationInfo appInfo = pm.getApplicationInfo(pakgename, PackageManager.GET_META_DATA);
//            return pm.getApplicationLabel(appInfo).toString();
//        } catch (PackageManager.NameNotFoundException e) {
//
//        }
//        return pakgename;

        return  "";
    }
}
